<?php
/**
 * Created by PhpStorm.
 * User: steven
 * Date: 2017/11/20
 * Time: 下午9:40
 */

namespace app\api\controller\v1;


use app\api\validate\Count;
use app\api\model\Product as ProductModel;
use app\api\validate\IDMustBePostiveInt;
use app\lib\exception\ProductException;

class Product {

    public function getRecent($count=15){
        (new Count())->goCheck();
        $products   = ProductModel::getMostRecent($count);

        if($products->isEmpty()){
            throw new ProductException();
        }
        // 这里需要在database里面设置一下呀
        // $collection = collection($products);
        $products = $products->hidden(['summary']);
        return $products;
    }

    public function getAllCategory($id){
        (new IDMustBePostiveInt())->gocheck();
        $products = ProductModel::getProductsByCategoryID($id);
        if($products->isEmpty()){
            throw new ProductException();
        }
        $products = $products->hidden(['summary']);
        return $products;
    }
}